package com.trsj.lnsj.config;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;

/**  

* <p>Title: JacksonObjectMapper.java</p>  

* <p>Description: </p>  

* <p>Copyright: Copyright (c) 2018</p>  

* <p>Company: 七色环</p>  

* @author longky  

* @date 2018年9月3日  

* @version 1.0  

*/
public class JacksonObjectMapper extends ObjectMapper {
	/**
	    * 
	    */
	    private static final long serialVersionUID = 1L;

	    public  JacksonObjectMapper() {
	    super();
	        // 数字也加引号
	        // this.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true);
	        // this.configure(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS,
	        // true);
	        // 空值处理为空串
	        this.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {

				@Override
				public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers)
						throws IOException, JsonProcessingException {
					// TODO Auto-generated method stub
					gen.writeString("");
				}
	        });

	    }

}

